/**
 * @functionName: postDownload
 * @Description: post请求下载文件
 * @author Sun Yan
 * @date $
 */

function postDownload (config) {
    // 创建iframe
    var iframe = document.createElement("iframe");
    iframe.setAttribute("id", "downFilePostIframe");
    iframe.setAttribute("name", "downFilePostIframe");
    iframe.setAttribute("enctype", "multipart/form-data");
    iframe.style.height = "0px";
    iframe.style.display = "none";
    // 创建form
    const form = document.createElement("form");
    form.setAttribute("target", "down-file-iframe");
    form.setAttribute("method", "post");
    form.setAttribute("id", "downFilePostForm");
    form.setAttribute("action", config.url);
    // 组装表单数据
    Object.keys(config.data).forEach((key) => {
        const input = document.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", key);
        input.setAttribute("value", config.data[key]);
        form.appendChild(input);
    });

    document.body.appendChild(iframe);
    document.body.appendChild(form);
    // 提交
    form.submit();
    // 删除iframe和表单
    document.body.removeChild(iframe);
    document.body.removeChild(form);
}


export {
    postDownload
}